/*
 * Copyright 2013-2016 Gephi Consortium
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.gephi.plugins.filter.kbrace;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.gephi.plugins.filter.kbrace.KBraceBuilder.KBraceFilter;
import org.gephi.filters.spi.FilterProperty;
import org.openide.util.WeakListeners;

/**
 *
 * @author Mathieu Bastian
 */
public class KBracePanel extends javax.swing.JPanel implements ChangeListener {

    private KBraceFilter filter;

    public KBracePanel() {
        initComponents();
    }

    public void stateChanged(ChangeEvent evt) {
        FilterProperty k = filter.getProperties()[0];
        try {
            k.setValue((Integer) degreeSpinner.getValue());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setup(KBraceFilter filter) {
        this.filter = filter;
        degreeSpinner.setModel(new javax.swing.SpinnerNumberModel(filter.getK(), Integer.valueOf(1), null, Integer.valueOf(1)));
        degreeSpinner.getModel().addChangeListener(WeakListeners.change(KBracePanel.this, degreeSpinner.getModel()));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        degreeSpinner = new javax.swing.JSpinner();

        setLayout(new java.awt.GridBagLayout());

        degreeSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1)));
        degreeSpinner.setPreferredSize(new java.awt.Dimension(65, 28));
        add(degreeSpinner, new java.awt.GridBagConstraints());
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSpinner degreeSpinner;
    // End of variables declaration//GEN-END:variables
}
